<?php
namespace Clover\Model;

use Think\Model;

class BooksModel extends Model
{
    /**
     * 获取用户权限
     *
     * @param number $role_id
     * @return string
     * @author KevinBai
     */
    protected $tableName = 'books';

    public function get_books_list($cat_id)
    {
        $map = array();
        if (!empty($cat_id)) {
            $map['cat_id'] = $cat_id;
        }
        $query = $this->table("dsk_books")->where($map)->order(array('sort_order' => "desc", 'add_time' => "asc"))->select();
        return $query;
    }

    /*
     * 获取无限分类ID下面的子类ID集
     *
    */
    public function get_Children_Ids($cat_id)
    {
        $ids = "";
        $sql = "SELECT * FROM dsk_news_category WHERE parent_id='{$cat_id}'";
        $result = $this->query($sql);
        if ($result) {
            foreach ($result as $k => $row) {
                $ids .= ',' . $row['id'];
                $ids .= $this->get_Children_Ids($row['id']);
            }
        }
        return $ids;
    }
}

?>